#ifndef BOARD_H
#define BOARD_H

#include <QWidget>
#include"qizi.h"
#include"Step.h"
#include<QVector>

class Board : public QWidget
{
    Q_OBJECT
public:
    explicit Board(QWidget *parent = nullptr);
    ~Board();

    qizi _s[32];
    int _r;
    QPoint _off;
    bool _bSide;

    QVector<Step*> _steps;

    int _selectid;
    bool _bRedTurn;
    void init(bool bRedSide);

    void paintEvent(QPaintEvent *);
    void drawPlate(QPainter& p);
    void drawPlace(QPainter& p);
    void drawInitPosition(QPainter& p);
    void drawInitPosition(QPainter& p, int row, int col);
    void drawqizi(QPainter& p);
    void drawqizi(QPainter& p, int id);

    QPoint center(int row, int col);
    QPoint center(int id);
    QPoint topLeft(int row, int col);
    QPoint topLeft(int id);
    QRect cell(int row, int col);
    QRect cell(int id);

    bool getClickRowCol(QPoint pt, int& row, int& col);

    QString name(int id);
    bool red(int id);
    bool samecolor(int id1, int id2);
    int getqiziId(int row, int col);
    void killqizi(int id);
    void reliveqizi(int id);
    void moveqizi(int moveid, int row, int col);
    bool isDead(int id);

    void mouseReleaseEvent(QMouseEvent *);
    void click(QPoint pt);
    virtual void click(int id, int row, int col);
    void tryselectqizi(int id);
    void trymoveqizi(int killid, int row, int col);
    void moveqizi(int moveid, int killid, int row, int col);
    void saveStep(int moveid, int killid, int row, int col, QVector<Step*>& steps);
    void backone();
    void back(Step* step);
    virtual void back();

    bool canMoveJIANG(int moveid, int killid, int row, int col);
    bool canMoveSHI(int moveid, int killid, int row, int col);
    bool canMoveXIANG(int moveid, int killid, int row, int col);
    bool canMove(int moveid, int killid, int row, int col);
    bool canMoveCHE(int moveid, int killid, int row, int col);
    bool canMoveMA(int moveid, int killid, int row, int col);
    bool canMovePAO(int moveid, int killid, int row, int col);
    bool canMoveBING(int moveid, int killid, int row, int col);

    bool canselect(int id);
    int getqiziCountAtline(int row1, int col1, int row2, int col2);
    bool isBottomSide(int id);

signals:

public slots:
    void slotBack();
};

#endif // BOARD_H
